import * as Cesium from '@cesiumjs';
import { G3V } from '@g3x';

const czmOptions = {
  imageryProvider: {
    type: 'arcgisImagery',
    options: {
      brightness: 1,
      show: true
    }
  },
  terrainProvider: {
    type: 'default',
    options: {
      requestVertexNormals: true,
      requestWaterMask: true
    }
  },
  shadows: false
};

const g3vOptions = {
  navigation: {
    // defaultResetView: G3V.defaultViews.global.china.rectangle ,
    defaultResetView: null //flyHome
  },
  globe: {
    depthTestAgainstTerrain: false,
    enableLighting: true //启用以太阳为光源的地球
  },
  hideLayers: false,
  layers: [
    // { type: 'tdtImgAnno', options: { brightness: 1, show: true } },
    {
      type: 'graticule',
      options: {
        brightness: 1,
        show: true
      }
    }
  ]
};

let minxins = {
  data() {
    return {
      playing: true,
      g3v: null,
      sliderOption: { min: 0, max: 3600 * 24, step: 1 },
    };
  },
  computed: {
    viewer() {
      return this.g3v && this.g3v.viewer;
    },
    viewerSource() {
      const {
        viewer
      } = this;
      return {
        viewer
      };
    },
    clockOptions() {
      return {
        multiplier: 1
      };
    },
    czmOptions() {
      return undefined
    },
    g3vOptions() {
      return undefined
    }
  },
  mounted() {
    this.initViewer();
  },
  beforeUnmount() {},
  unmounted() {
    this.onUnmounted();
    this.g3v && this.g3v.destroy();
    this.g3v = null;
  },
  methods: {
    onUnmounted() {},
    initViewer() {
      let vm = this;
      this.g3v = new G3V(vm);
      var viewer = this.g3v.create('cesium-viewer', this.czmOptions || czmOptions, this.g3vOptions || g3vOptions);
      Cesium.GroundPrimitive.initializeTerrainHeights().then(() => {
        vm.onViewerInited(viewer);
        vm.initEffects();
      });
    },
    onViewerInited(viewer) {},
    initEffects() {},
  },
};

export default minxins;

export {
  minxins,
  czmOptions,
  g3vOptions
}
